import axios from "axios";
import store from "@/store";

const service = axios.create({
	baseURL: "",
	timeout: 5000
});

// 请求拦截
service.interceptors.request.use(
	config => {
		if (store.getters.token) {
			config.headers["X-Token"] = store.getters.token;
		}
		return config;
	},
	error => {
		console.log(error);
		return Promise.reject(error);
	}
);

// 响应拦截
service.interceptors.response.use(response => response.data);
export default service;
